package com.wb.web.controller.exams;


import com.wb.common.core.controller.BaseController;
import com.wb.common.core.domain.AjaxResult;
import com.wb.common.core.page.TableDataInfo;
import com.wb.common.vo.DeleteRequest;
import com.wb.common.vo.ExamSchedulesModelVO;
import com.wb.common.vo.ExamsLevelModelVO;
import com.wb.system.domain.ExamSchedulesEntity;
import com.wb.system.domain.ExamsLevelEntity;
import com.wb.system.service.ExamSchedulesService;
import com.wb.system.service.ExamsLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("exams/schedules")
@Api(tags = "考试时间表")
public class ExamScheduleslController extends BaseController {
    @Autowired
    private ExamSchedulesService examSchedulesService;

    @PostMapping("/list")
    @ApiOperation("考试时间表列表")
    public TableDataInfo list(@RequestBody ExamSchedulesModelVO vo) {
        startPage();
        List<ExamSchedulesEntity> list = examSchedulesService.selectExamSchedulesList(vo);
        return getDataTable(list);
    }


    @GetMapping("/{id}")
    @ApiOperation("获取考试时间表详情")
    public AjaxResult get(@PathVariable("id") Long id) {
        return AjaxResult.success(examSchedulesService.selectById(id));
    }

    @PostMapping("/add")
    @ApiOperation("考试时间表创建")
    public AjaxResult add(@Valid @RequestBody ExamSchedulesEntity ExamSchedulesModelVO) {
        ExamSchedulesEntity ExamSchedulesEntity = new ExamSchedulesEntity();
        BeanUtils.copyProperties(ExamSchedulesModelVO, ExamSchedulesEntity);
        examSchedulesService.saveExamSchedules(ExamSchedulesEntity);
        return AjaxResult.success();
    }


    @PostMapping("/update")
    @ApiOperation("更新考试时间表")
    public AjaxResult update(@RequestBody ExamSchedulesEntity ExamSchedulesModelVO) {
        ExamSchedulesEntity ExamSchedulesEntity = new ExamSchedulesEntity();
        BeanUtils.copyProperties(ExamSchedulesModelVO, ExamSchedulesEntity);
        examSchedulesService.updateExamSchedulesById(ExamSchedulesEntity);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteAll")
    @ApiOperation("删除All")
    public AjaxResult deleteAll(@RequestBody DeleteRequest request) {
        examSchedulesService.removeExamSchedulesByIds(request.getIds());
        return AjaxResult.success();
    }
}
